package com.ljx.offer;

import org.junit.Test;

import java.sql.Array;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/3/22
 * ClassName: C_62
 */

public class C_62 {
    /**
     *
     * @param n
     * @param m
     * @return
     */
    public int lastRemaining(int n, int m) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(i);
        }
        int index = 0;
        while (n > 1){
            index = (index + m - 1) % n;
            list.remove(index);
            n--;
            }
        return list.get(0);
    }

    @Test
    public void test(){
        System.out.println(lastRemaining(5, 3));

    }

}
